package ModelLayer;
import java.util.*;
import java.text.*;


public class Note{
    public void generateSaleInvoice(int saleId){
        Sale sale = SaleContainer.getInstance().findSaleById(saleId);
        Date dNow = new Date( );
        SimpleDateFormat ft =  new SimpleDateFormat ("dd/MM/yyyy");

        System.out.println("Employee ID:" + sale.getEmployeeID());
        System.out.println("Employee name:" + EmployeeContainer.getInstance().findEmployeeById(sale.getEmployeeID()).getName());
        System.out.println("Sale date:" + sale.getDate());
        System.out.println("Customer ID:" + sale.getCustomerID());
        System.out.println("Customer name:"+ CustomerContainer.getInstance().findCustomerById(sale.getCustomerID()).getName());
        System.out.println("Customer address:" + CustomerContainer.getInstance().findCustomerById(sale.getCustomerID()).getAddress());
        double priceBeforeDiscount = 0;

        System.out.println("---------------Products:----------------------");
        for (int key :  SaleContainer.getInstance().findSaleById(saleId).getProducts().keySet()) {
            System.out.println("Product: " + key + "\t  Amount: " + SaleContainer.getInstance().findSaleById(saleId).getProducts().get(key)+
                "\t  Unit Price: " + ProductContainer.getInstance().findProductByBarcode(key).getSellingPrice()+ 
                "\t Price: " + ProductContainer.getInstance().findProductByBarcode(key).getSellingPrice()*SaleContainer.getInstance().findSaleById(saleId).getProducts().get(key));
            priceBeforeDiscount+=ProductContainer.getInstance().findProductByBarcode(key).getSellingPrice()*SaleContainer.getInstance().findSaleById(saleId).getProducts().get(key);
        }
        System.out.println("----------------------------------------------");

        System.out.println("Total without discount:" +  priceBeforeDiscount);
        System.out.println("Discount:" +  CustomerContainer.getInstance().findCustomerById(sale.getCustomerID()).getDiscount() + "%");
        System.out.println("Total:" +  sale.getTotalPrice());

        System.out.println("Date: " + ft.format(dNow));
        System.out.println("----------------------------------------------");
    }

    public void generateLeaseInvoice(int leaseId){
        Lease lease = LeaseContainer.getInstance().findLeaseById(leaseId);
        Date dNow = new Date( );
        SimpleDateFormat ft =  new SimpleDateFormat ("dd/MM/yyyy");
        System.out.println("Employee ID:" + lease.getEmployeeID());
        System.out.println("Employee name:" + EmployeeContainer.getInstance().findEmployeeById(lease.getEmployeeID()).getName());
        System.out.println("Lease date:" + lease.getCurrentDate());
        System.out.println("Customer ID:" + lease.getCustomerID());
        System.out.println("Customer name:"+ CustomerContainer.getInstance().findCustomerById(lease.getCustomerID()).getName());
        System.out.println("Customer address:" + CustomerContainer.getInstance().findCustomerById(lease.getCustomerID()).getAddress());
        double priceBeforeDiscount = 0;
        System.out.println("---------------Products:----------------------");
        for (int key :  LeaseContainer.getInstance().findLeaseById(leaseId).getProducts().keySet()) {
            System.out.println("Product: " + key + "\t  Amount: " + LeaseContainer.getInstance().findLeaseById(leaseId).getProducts().get(key)+
                "\t  Unit Price: " + ProductContainer.getInstance().findProductByBarcode(key).getLeasingPrice()+ 
                "\t Price: " + ProductContainer.getInstance().findProductByBarcode(key).getLeasingPrice()*LeaseContainer.getInstance().findLeaseById(leaseId).getProducts().get(key));
            priceBeforeDiscount+=ProductContainer.getInstance().findProductByBarcode(key).getLeasingPrice()*LeaseContainer.getInstance().findLeaseById(leaseId).getProducts().get(key);
        }
        System.out.println("----------------------------------------------");
        System.out.println("Total:" +  lease.getTotalPrice());
        System.out.println("Date: " + ft.format(dNow));
        System.out.println("----------------------------------------------");
    }

    public void generateDispatchNote(int deliveryId){
        Delivery delivery = DeliveryContainer.getInstance().findDeliveryById(deliveryId);
        Date dNow = new Date( );
        SimpleDateFormat ft =  new SimpleDateFormat ("dd/MM/yyyy");

        System.out.println("Employee ID:" + delivery.getEmployeeID());
        System.out.println("Employee name:" + EmployeeContainer.getInstance().findEmployeeById(delivery.getEmployeeID()).getName());
        System.out.println("DeliveryId ID:" + delivery);
        System.out.println("Sale date:" + delivery.getDate());
        System.out.println("Customer ID:" + delivery.getCustomerID());
        System.out.println("Customer name:"+ CustomerContainer.getInstance().findCustomerById(delivery.getCustomerID()).getName());
        System.out.println("Customer address:" + CustomerContainer.getInstance().findCustomerById(delivery.getCustomerID()).getAddress());
        double priceBeforeDiscount = 0;

        System.out.println("---------------Products:----------------------");
        for (int key :  DeliveryContainer.getInstance().findDeliveryById(deliveryId).getProducts().keySet()) {
            System.out.println("Product: " + key + "\t  Amount: " + DeliveryContainer.getInstance().findDeliveryById(deliveryId).getProducts().get(key));
            priceBeforeDiscount+=ProductContainer.getInstance().findProductByBarcode(key).getSellingPrice()*DeliveryContainer.getInstance().findDeliveryById(deliveryId).getProducts().get(key);
        }
        System.out.println("----------------------------------------------");

        System.out.println("Date: " + ft.format(dNow));
        System.out.println("----------------------------------------------");
        System.out.println("Sign:_______ \t\t\t");
    }

    public void generateDeliveryNote(int deliveryId){
        Delivery delivery = DeliveryContainer.getInstance().findDeliveryById(deliveryId);
        Date dNow = new Date( );
        SimpleDateFormat ft =  new SimpleDateFormat ("dd/MM/yyyy");

        System.out.println("Employee ID:" + delivery.getEmployeeID());
        System.out.println("Employee name:" + EmployeeContainer.getInstance().findEmployeeById(delivery.getEmployeeID()).getName());
        System.out.println("Sale date:" + delivery.getDate());
        System.out.println("Customer ID:" + delivery.getCustomerID());
        System.out.println("Customer name:"+ CustomerContainer.getInstance().findCustomerById(delivery.getCustomerID()).getName());
        System.out.println("Customer address:" + CustomerContainer.getInstance().findCustomerById(delivery.getCustomerID()).getAddress());
        double priceBeforeDiscount = 0;

        System.out.println("---------------Products:----------------------");
        for (int key :  DeliveryContainer.getInstance().findDeliveryById(deliveryId).getProducts().keySet()) {
            System.out.println("Product: " + key + "\t  Amount: " + DeliveryContainer.getInstance().findDeliveryById(deliveryId).getProducts().get(key));
            priceBeforeDiscount+=ProductContainer.getInstance().findProductByBarcode(key).getSellingPrice()*DeliveryContainer.getInstance().findDeliveryById(deliveryId).getProducts().get(key);
        }
        System.out.println("----------------------------------------------");

        System.out.println("Delivery costs:" + delivery.getPrice());
        System.out.println("Date: " + ft.format(dNow));
        System.out.println("----------------------------------------------");
        System.out.println("Sign:_______ \t\t\t Sign:_______");
    }
}
